var app = getApp();
var that;

Page({
  data: {
    textcolor: "#aaa",
    border: "#ccc",
    text1color: "#aaa",
    border1: "#ccc",
    orderlist: [],
    loadingHidden: false,
    isJzwb: false,
    isJzz: false,
    kong: true
  },
  navbarTap: function(e) {
    this.currentTab = e.currentTarget.dataset.idx
    console.log(this.data.currentTab)
    this.setData({
      currentTab: this.data.currentTab,
    })
  },
  onLoad: function(options) {
    // this.currentTab = options.id;
    // console.log(this.currentTab)
    // if (this.currentTab == 1) {//判断id值等于1显示待支付
    //   this.setData({
    //     currentTab: Number(this.currentTab),
    //   })
    // } else if (this.currentTab == 3) {
    //   this.setData({
    //     currentTab: Number(this.currentTab),
    //   })
    // } else {
    //   this.setData({
    //     currentTab: 0,
    //   })
    // }
    that = this;
    var bizUserInfoid = (wx.getStorageSync('bizUserInfo').id)
   wx.request({
      url: app.api.getshopOrder(),
      method: "POST",
      data: {
        "limit": 10,
        "ordStatus": '',
        "ordType": 2,
        "page": 1,
        "custId": bizUserInfoid //会员id
      },

      success: function(res) {

        if (res.statusCode == 200 && res.errMsg == 'request:ok') {
          if (res.data.code == 1) {
            var list = res.data.list
            if (res.data.code == 1) {
              if (list.length == 0) {
                that.setData({
                  kong: false
                })
              } else {
                that.setData({
                  loadingHidden: true,
                  orderlist: list
                })
              }
            } else {
              wx.showToast({
                title: res.data.message,
              })
            }

          } else {
            wx.showToast({
              title: res.data.message,
            })
          }
        }
      }
    })
    if (that.data.orderlist.length == that.data.orderlist.length) {
      that.setData({
        isJzz: true
      })
    }
  },

  deleshop(e) {
    that = this
    console.log(e.currentTarget.dataset.id)
    // var deleordId = e.currentTarget.dataset.id
    wx.showModal({
      title: '温馨提示',
      content: '确定删除兑换记录',
      success: function(res) {
        if (res.confirm) {
          wx.request({
            url: app.api.getjfDeleorder(),
            method: 'GET',
            data: {
              ordId: e.currentTarget.dataset.id
            },

            success: function(res) {

              if (res.statusCode == 200 && res.errMsg == 'request:ok') {
                if (res.data.code == 1) {
                  wx.showToast({
                    title: '删除成功',
                    icon: "success",
                  })
                  that.onLoad()
                  that.setData({
                    orderlist:[]
                  })
                } else {
                  wx.showToast({
                    title: res.data.message,
                  })
                }
              }
            }

          })
        } else {
          console.log('取消')
        }
      }
    })

  },
  confirmShop(e) { //确认收货按钮
    that = this
    console.log(e.currentTarget.dataset.id)
    var shopordid = e.currentTarget.dataset.id
    wx.request({
      // url: 'http://172.188.88.232:8080/order/setStatus',
      url: app.api.getshopbtnsuccess(),
      method: 'POST',
      data: {
        ordStatus: 4,
        ordId: shopordid
      },

      success: function(res) {

        if (res.statusCode == 200 && res.errMsg == 'request:ok') {
          if (res.data.code == 1) {
            wx.showToast({
                title: '交易成功',
                icon: "success",
              })
            that.onLoad()
            that.setData({
              orderlist: []
            })
          } else {
            wx.showToast({
              title: res.data.message,
            })
          }
        }
      }
    })
  },
  btn1() {
    this.setData({
      textcolor: "#000",
      border: "#ff3333"
    })
  },
  btn2() {
    this.setData({
      text1color: "#000",
      border1: "#ff3333"
    })
  },
  onReady: function() {},
  onShow: function() {},
  onHide: function() {},
  onUnload: function() {},
  onPullDownRefresh: function() {}
});